package com.example.mdemo.animator;

import android.animation.ObjectAnimator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;

import com.example.mdemo.R;

/**
 * 缩放 scaleX，scaleY
 * 旋转 rotationX， rotationY
 * 平移 translationX，translationY, X，Y
 * 透明度 alpha
 */

public class AnimatorActivity extends AppCompatActivity {

    private ImageView img;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animator);
        img = (ImageView) findViewById(R.id.img);
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startAnimator();
            }
        });
    }

    private void startAnimator() {
        ObjectAnimator.ofFloat(img,"translationX",0,300,200,400)
                .setDuration(2*1000)
                .start();
        ObjectAnimator.ofFloat(img,"translationY",0,200,50,300)
                .setDuration(2*1000)
                .start();
        ObjectAnimator.ofFloat(img,"rotationX",0,180)
                .setDuration(2*1000)
                .start();
        ObjectAnimator.ofFloat(img,"rotationY",0,360)
                .setDuration(2*1000)
                .start();
    }


}
